package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.ReturnListGoodsService;
import com.atguigu.jxc.service.SaleListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: SaleListGoodsController
 * Description:
 * Date: 2022/1/17 21:09
 *
 * @version:
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/saleListGoods")
public class SaleListGoodsController {

    @Autowired
    private SaleListGoodsService saleListGoodsService;

    @PostMapping("/save")
    public ServiceVO saveSaleListGoods(SaleList saleList, String saleListGoodsStr, HttpSession session){

        try {
            saleListGoodsService.saveSaleListGoods(saleList,saleListGoodsStr,session);
            return new ServiceVO<>(100,"请求成功");

        }catch (Exception e){
            e.printStackTrace();
        }

        return new ServiceVO<>(101,"添加或修改失败");
    }


    @PostMapping("/list")
    public Map<String,Object> getsaleListGoods(String saleNumber, Integer customerId, Integer state, String sTime,String eTime){
        List<SaleList> saleListList = saleListGoodsService.getSaleListGoods(saleNumber,customerId,state,sTime,eTime);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",saleListList);
        return stringObjectHashMap;
    }


    @PostMapping("/goodsList")
    public Map<String,Object> getGoodsList(Integer saleListId){
        List<SaleListGoods> saleListGoodsList = saleListGoodsService.getGoodsList(saleListId);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",saleListGoodsList);
        return stringObjectHashMap;
    }

    @PostMapping("/delete")
    public ServiceVO deleteSaleListGoods(Integer saleListId){
        try {
            saleListGoodsService.deleteSaleListGoods(saleListId);
            return new ServiceVO<>(100,"请求成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"删除失败");


    }


    @PostMapping("/updateState")
    public ServiceVO updateState(Integer saleListId){
        try {
            saleListGoodsService.updateState(saleListId);
            return new ServiceVO<>(100,"请求成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"请求失败");


    }


    @PostMapping("/count")
    public List<saleListGoodsCount> count(String sTime, String eTime , Integer goodsTypeId, String codeOrName){



        List<saleListGoodsCount> saleListGoodsCountList = saleListGoodsService.count(sTime, eTime ,goodsTypeId, codeOrName);


        return saleListGoodsCountList;

    }


    @PostMapping("/getSaleDataByDay")
    public List<SaleDataByDay> getSaleDataByDay(String sTime, String eTime){



        List<SaleDataByDay> saleDataByDay = saleListGoodsService.getSaleDataByDay(sTime, eTime);


        return saleDataByDay;

    }


    @PostMapping("/getSaleDataByMonth")
    public List<SaleDataByDay> getSaleDataByMonth(String sTime, String eTime){



        List<SaleDataByDay> saleDataByMonth = saleListGoodsService.getSaleDataByMonth(sTime, eTime);


        return saleDataByMonth;

    }

}
